package com.itheima.reggie.controller;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.itheima.reggie.common.R;
import com.itheima.reggie.dto.DishDto;
import com.itheima.reggie.entity.Dish;
import com.itheima.reggie.service.IDishService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 菜品管理 前端控制器
 * </p>
 *
 * @author 
 * @since 2024-05-22
 */
@Slf4j
@RestController
@RequestMapping("/dish")
public class DishController {
    @Autowired
    public IDishService service;

    @GetMapping("page")
    public R<Page> pageQuery(Integer page,Integer pageSize,String name){
        return service.pageQuery(page,pageSize,name);
    }

    /**
     * 菜品修改前的回显
     * @param id
     * @return
     */
    @GetMapping("/{id}")
    public R<DishDto> queryDishAndDishFlavorById(@PathVariable Long id){
        log.info("传入参数id:{}",id);
        return service.queryDishAndDishFlavorById(id);
    }

    /**
     * 添加菜品
     * @param dishDto
     * @return
     */
    @PostMapping
    public R<String> saveDishAndDishFlavor(@RequestBody DishDto dishDto){
        return service.saveDishAndDishFlavor(dishDto);
    }

    /**
     * 修改菜品
     * @param dishDto
     * @return
     */
    @PutMapping
    public R<String> updateDishAndDishFlavor(@RequestBody DishDto dishDto){
        return service.saveDishAndDishFlavor(dishDto);
    }

    @GetMapping("/list")
    public R<List<DishDto>> queryByCategoryIdAndStatus(Long categoryId,Integer status){
        return service.queryByCategoryIdAndStatus(categoryId,status);
    }

    @DeleteMapping
    public R<String> delete(@RequestParam List<Long> ids){
        return service.delete(ids);
    }
}
